import behaviors from "../../../../config/behaviors";
import ImageModel from "../../../../models/Image";
import constant from "../../../../config/constant";


const imageModel = new ImageModel()

Component({
  behaviors: [behaviors],
  properties: {
    image: String,
    user: {
      type: Object,
      value: {},
      observer(newVal, oldVal, changedPath) {
        if (newVal.level0 && newVal.level0.display) {
          let name = newVal.level0.display
          // if (newVal.level0.key === 'v1') {
          //   name = '店主'
          // }
          this.setData({ levelName: name })
          this.setData({
            wx: getApp().globalData.wx
          })
        }
      }
    },
    wx: Boolean
  },
  data: {
    levelName: '',
    wx: false
  },
  methods: {
    clearCache() {
      // 清理缓存, 但要保留user token

      // image
      wx.removeStorageSync(imageModel.getKey())

      // referrer id
      wx.removeStorageSync(constant.referrerKey)

      wx.removeStorageSync('update_avatar')

      wx.showToast({
        title: '清除成功',
        duration: 1000
      })
    },

    // 联系客服
    handleContact() {

    },

    // 互转
    onTransfer() {
      wx.navigateTo({
        url: '/sub_common/pages/transfer/index'
      })
    },

    goService() {
      wx.navigateTo({
        url: '/sub_common/pages/service/index'
      })
    },

    // 修改头像
    goAvatar() {
      wx.navigateTo({
        url: '/sub_main/pages/user/avatar/index'
      })
    }
  }
});
